package com.test.netty.demo;

import com.test.netty.demo.server.HttpServer;
import com.test.netty.demo.server.impl.HttpServerImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication implements CommandLineRunner {

    @Value("${server.port}")
    private int port;

    public static void main(String[] args) {
        // 创建容器
        SpringApplication.run(DemoApplication.class, args);
    }

    @Override
    public void run(String... args) {
        // 启动服务
        HttpServer httpServer = new HttpServerImpl(port);
        // Java优雅关机
        Runtime.getRuntime().addShutdownHook(new Thread(httpServer::stop));
        httpServer.start();
    }

}
